/***************************************************************************
 *   This is a part of the NextCAD Web APP.                                *
 *   Copyright (C) AMCAX, All rights reserved.                             *
 ***************************************************************************/

// import { Alert, Button } from 'antd';
import i18n from 'i18next';

import { CommandDialog } from '@amcax/base';
import { CommandLabeledItemWrapper } from '@app-cad/common/components/command-form/item-wrapper';
import { CurvedBaseCommand, CurvedCmdDialogParams } from '@app-cad/types';
import { Select } from 'antd';
import { useState, useEffect } from 'react';
import { Draft } from './draft';
import { Reference } from './reference';
import { Explicit } from './explicit';

function DisplaySweepDialog({ title, onClose, props }: CurvedCmdDialogParams) {
  const [mode, setMode] = useState<
    'DraftDirection' | 'ReferenceSurface' | 'TwoGuideCurves'
  >('DraftDirection');

  const [editProps, setEditProps] = useState<any>();
  const [editDxid, setEditDxid] = useState<string>();

  useEffect(() => {
    setMode(props?.params?.mode ?? 'DraftDirection');
    setEditProps(props);
    setEditDxid(props?.shape);
  }, [props?.shape]);

  return (
    <CommandDialog
      title={title}
      onClose={onClose}
      placement='topLeft'>
      <CommandLabeledItemWrapper
        className='mt-5 px-5'
        label='类型'>
        <Select
          options={[
            { value: 'DraftDirection', label: '拔模方向' },
            { value: 'ReferenceSurface', label: '使用参考曲面' },
            { value: 'TwoGuideCurves', label: '两条引导曲线' },
          ]}
          value={mode}
          onChange={(val) => {
            if (val !== mode) {
              setMode(val);
              setEditProps(null);
            }
          }}
        />
      </CommandLabeledItemWrapper>
      {mode === 'DraftDirection' && (
        <Draft
          props={editProps}
          onClose={onClose}
          editDxid={editDxid}
        />
      )}
      {mode === 'ReferenceSurface' && (
        <Reference
          props={editProps}
          onClose={onClose}
          editDxid={editDxid}
        />
      )}
      {mode === 'TwoGuideCurves' && (
        <Explicit
          props={editProps}
          onClose={onClose}
          editDxid={editDxid}
        />
      )}
    </CommandDialog>
  );
}

export const cmdDisplaySweepSurface: CurvedBaseCommand = {
  id: 'CmdDisplaySweep',
  label: 'command.display-sweep',
  icon: 'commands/curved/display-draft-sweep-surface',
  help: {
    remark: 'tips.redo',
  },
  create: (label, onClose, props) => (
    <DisplaySweepDialog
      title={i18n.t(label)}
      onClose={onClose}
      props={props}
    />
  ),
};
